package com.stormrage.edu.serv.edu.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.stormrage.edu.dao.edu.EduProjectDao;
import com.stormrage.edu.serv.edu.EduMajorServ;
import com.stormrage.edu.serv.edu.EduProjectServ;
import com.stormrage.entity.edu.EduProject;
import com.stormrage.entity.edu.rep.EduProjectRep;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @Title: EduProjectServImpl.java
 * @Package com.stormrage.edu.serv.edu.impl
 * @Description: 项目 Service
 * @author www.stormragetech.com
 * @date 2016年4月16日
 * @version V1.0
 */
@Service
public class EduProjectServImpl implements EduProjectServ {

	private static final Logger logger = LoggerFactory.getLogger(EduProjectServImpl.class);

	@Autowired
	private EduProjectDao eduProjectDao;

	@Autowired
	private EduMajorServ eduMajorServ;

	@Override
	public EduProject queryById(Integer id) throws StormrageTechException {

		logger.debug(" 【 Serv 】-【 EduProjectDao 】-【 QueryById 】-【 STARTED 】");

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);

		EduProject entity = eduProjectDao.queryById(map);

		logger.debug(" 【 Dao 】-【 EduProjectDao 】-【 QueryById 】-【 COMPLETED 】");
		return entity;

	}

	@Override
	public List<EduProject> queryList() throws StormrageTechException {

		logger.debug(" 【 Serv 】-【 EduProjectDao 】-【 QueryList 】-【 STARTED 】");

		List<EduProject> array = eduProjectDao.queryList();

		logger.debug(" 【 Dao 】-【 EduProjectDao 】-【 QueryList 】-【 COMPLETED 】");
		return array;
	}

	@Override
	public List<EduProjectRep> queryRepList() throws StormrageTechException {

		logger.debug(" 【 Serv 】-【 EduProjectDao 】-【 queryListForProj 】-【 STARTED 】");

		List<EduProject> array = eduProjectDao.queryList();

		List<EduProjectRep> list = new ArrayList<EduProjectRep>();
		int seq = 1;

		Iterator<EduProject> it = array.iterator();
		while (it.hasNext()) {
			EduProject proj = it.next();
			Integer count = eduMajorServ.queryCountByProjectId(proj.getId());
			EduProjectRep rep = EduProjectRep.instance(proj, seq, count);
			list.add(rep);
			seq++;
		}

		logger.debug(" 【 Dao 】-【 EduProjectDao 】-【 queryListForProj 】-【 COMPLETED 】");
		return list;

	}

}
